package cn.net.dpi.core.exception;

/**
 * 基础异常类
 */
public class BaseException extends RuntimeException {
    private ApiError error;
    private Object detail;
    private String msg;
    private Integer code;

    protected BaseException(ApiError error) {
        super(String.format("%s-%s", error.getCode(), error.getMessage()));
        this.error = error;
        this.code = error.getCode();
        this.msg = error.getMessage();
    }

    protected BaseException(ApiError error, String message) {
        super(String.format("%s-%s", error.getCode(), message));
        this.error = error;
        this.code = error.getCode();
        this.msg = message;
    }

    protected BaseException(ApiError error, Object detail) {
        super(String.format("%s-%s:%s", error.getCode(), error.getMessage(), detail));
        this.error = error;
        this.code = error.getCode();
        this.msg = error.getMessage();
        this.detail = detail;
    }

    protected BaseException(Integer code, String message) {
        super(String.format("%d-%s", code, message));
        this.code = code;
        this.msg = message;
    }

    protected BaseException(String message) {
        super(message);
    }

    public ApiError getError() {
        return this.error;
    }

    public Object getDetail() {
        return this.detail;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
